package com.evil.common.activiti.enums;

import com.evil.common.core.enums.RCodeEnum;
import com.evil.common.core.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 审批类型
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@AllArgsConstructor
public enum ApprovalTypeEnum {

    /**
     * 审批类型
     */
    ANYONE_PASS(0, "或签"),
    ALL_PASS(1, "会签"),
    ;

    @Getter
    private final int id;
    @Getter
    private final String name;

    public static Optional<ApprovalTypeEnum> findById(Integer id) {
        if (null == id) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.id == id).findFirst();
    }

    public static ApprovalTypeEnum isExistById(Integer id) {
        return ApprovalTypeEnum.findById(id).orElseThrow(() ->
                new BusinessException(RCodeEnum.ERROR_PARAMETER, "审批类型参数错误"));
    }
}
